<?php

/*
 * Copyright 2008 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#namespace tehframework\annotations;

class DocBlockDefinition
{
	/**
	 * @var string?
	 */
	public $shortDescription;
	
	/**
	 * @var string?
	 */
	public $longDescription;
	
	/**
	 * @var TagDefinition[]
	 */
	public $tagDefinitions;
	
	/**
	 * @var AnnotationDefinition[] $annotationDefinitions
	 */
	public $annotationDefinitions;
	
	/**
	 * @param string? $shortDescription
	 * @param string? $longDescription
	 * @param TagDefinition[] $tagDefinitions
	 * @param AnnotationDefinition[] $annotationDefinitions
	 */
	public function __construct(
		$shortDescription = null,
		$longDescription = null,
		array $tagDefinitions = array(),
		array $annotationDefinitions = array())
	{
		$this->shortDescription      = empty($shortDescription)
			? null : $shortDescription;
		$this->longDescription       = empty($longDescription)
			? null : $longDescription;
		$this->tagDefinitions        = $tagDefinitions;
		$this->annotationDefinitions = $annotationDefinitions;
	}
	
	/**
	 * @return string
	 */
	public function __toString()
	{
		$str = '';
		
		if (!empty($this->shortDescription))
		{
			$str .= $this->shortDescription . PHP_EOL . PHP_EOL;
		}
		
		if (!empty($this->longDescription))
		{
			$str .= $this->longDescription . PHP_EOL . PHP_EOL;
		}
		
		if (!empty($this->tagDefinitions))
		{
			foreach ($this->tagDefinitions as $tagDefinition)
			{
				$str .= $tagDefinition . PHP_EOL;
			}
		}
		
		if (!empty($this->annotationDefinitions))
		{
			foreach ($this->annotationDefinitions as $annotationDefinition)
			{
				$str .= $annotationDefinition . PHP_EOL;
			}
		}
		
		return $str;
	}
}